﻿<%@ Page Language="C#" MasterPageFile="~/default.Master" AutoEventWireup="true" CodeBehind="AddBook.aspx.cs"
    Inherits="BookNet.WebForm3" Title="List a new book" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>List a new book</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>" DeleteCommand="DELETE FROM [app_Books] WHERE [BookID] = @original_BookID"
        InsertCommand="INSERT INTO [app_Books] ([Author], [Seller], [Title], [Description], [Price], [TimeAdded], [CoverImageUrl], [ForLending], [Condition], [ISBN]) VALUES (@Author, @Seller, @Title, @Description, @Price, @TimeAdded, @CoverImageUrl, @ForLending, @Condition, @ISBN)"
        OldValuesParameterFormatString="original_{0}" OnSelecting="SqlDataSource1_Selecting"
        SelectCommand="SELECT * FROM [app_Books]"
        oninserting="SqlDataSource1_Inserting" 
        
        UpdateCommand="UPDATE [app_Books] SET [Seller] = @Seller, [Title] = @Title, [Description] = @Description, [Price] = @Price, [TimeAdded] = @TimeAdded, [CoverImageUrl] = @CoverImageUrl, [ForLending] = @ForLending, [Condition] = @Condition, [ISBN] = @ISBN WHERE [BookID] = @original_BookID" 
        oninserted="SqlDataSource1_Inserted">
        <DeleteParameters>
            <asp:Parameter Name="original_BookID" Type="Object" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Seller" Type="Object" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="Price" Type="Decimal" />
            <asp:Parameter Name="TimeAdded" Type="DateTime" />
            <asp:Parameter Name="CoverImageUrl" Type="String" />
            <asp:Parameter Name="ForLending" Type="Boolean" />
            <asp:Parameter Name="Condition" Type="String" />
            <asp:Parameter Name="ISBN" Type="Int64" />
            <asp:Parameter Name="original_BookID" Type="Object" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Seller" />
            <asp:Parameter Name="Author" Type="String" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="Price" Type="Decimal" />
            <asp:Parameter Name="TimeAdded" Type="DateTime" />
            <asp:Parameter Name="CoverImageUrl" Type="String" />
            <asp:Parameter Name="ForLending" Type="Boolean" />
            <asp:Parameter Name="Condition" Type="String" />
            <asp:Parameter Name="ISBN" Type="Int64" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <br /><br />
        <h3>Add New Title</h3>
    <p>&nbsp;</p>
            <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="651px" 
                AutoGenerateRows="False" DataKeyNames="BookID" 
                DataSourceID="SqlDataSource1" DefaultMode="Insert">
                <Fields>
                    <asp:TemplateField HeaderText="ISBN" SortExpression="ISBN">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ISBN") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ISBN") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
                            &nbsp;<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">I&#39;m lazy</asp:LinkButton>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("ISBN") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Title" SortExpression="Title">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Title") %>' 
                                Width="350px"></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Author" SortExpression="Author">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Author") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Author") %>' 
                                Width="350px"></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Author") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Condition" HeaderText="Condition" 
                        SortExpression="Condition" />
                    <asp:TemplateField HeaderText="Price" SortExpression="Price">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Price") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Price") %>'></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("Price") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="TimeAdded" HeaderText="Time Added" 
                        SortExpression="TimeAdded" Visible="False" />
                    <asp:TemplateField HeaderText="Cover Image Url" SortExpression="CoverImageUrl">
                        <InsertItemTemplate>
                        <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("CoverImageUrl") %>'></asp:TextBox>
                        <asp:Panel ID="Panel1" runat="server" Height="142px" Width="95px">
                            <asp:Image ID="Image1" runat="server" Width="95" Height="142" />
                            </asp:Panel>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label6" runat="server" Text='<%# Bind("CoverImageUrl") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CheckBoxField DataField="ForLending" HeaderText="For Lending" 
                        SortExpression="ForLending" />
                    <asp:TemplateField HeaderText="Description" SortExpression="Description">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Height="196px" 
                                Text='<%# Bind("Description") %>' Width="596px"></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Height="196px" 
                                Text='<%# Bind("Description") %>' Width="500px"></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>
            <br />
            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <ProgressTemplate>
                <center>
                    <img alt="loading" src="images/loading.gif" 
                        style="width: 128px; height: 15px; text-align: center" />
                        </center>
                </ProgressTemplate>
            </asp:UpdateProgress>
            <p>
                </p>
            <p>
                &nbsp;</p>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
